package emulator.unittest.hardware.nmos6502.timing;


import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;

public class AbsoluteXTest {

	@Test
	public void testADC() throws EmulatorException
	{
		int opcode = 0x7D;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testAND() throws EmulatorException
	{
		int opcode = 0x3D;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testASL() throws EmulatorException
	{
		int opcode = 0x1E;
		assertEquals(7, getCycles(opcode, false));
		assertEquals(7, getCycles(opcode, true));
	}
	
	@Test
	public void testCMP() throws EmulatorException
	{
		int opcode = 0xDD;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testDEC() throws EmulatorException
	{
		int opcode = 0xDE;
		assertEquals(7, getCycles(opcode, false));
		assertEquals(7, getCycles(opcode, true));
	}
	
	@Test
	public void testEOR() throws EmulatorException
	{
		int opcode = 0x5D;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testINC() throws EmulatorException
	{
		int opcode = 0xFE;
		assertEquals(7, getCycles(opcode, false));
		assertEquals(7, getCycles(opcode, true));
	}
	
	@Test
	public void testLDA() throws EmulatorException
	{
		int opcode = 0xBD;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testLDY() throws EmulatorException
	{
		int opcode = 0xBC;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testLSR() throws EmulatorException
	{
		int opcode = 0x5E;
		assertEquals(7, getCycles(opcode, false));
		assertEquals(7, getCycles(opcode, true));
	}
	
	@Test
	public void testORA() throws EmulatorException
	{
		int opcode = 0x1D;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testROL() throws EmulatorException
	{
		int opcode = 0x3E;
		assertEquals(7, getCycles(opcode, false));
		assertEquals(7, getCycles(opcode, true));
	}
	
	@Test
	public void testROR() throws EmulatorException
	{
		int opcode = 0x7E;
		assertEquals(7, getCycles(opcode, false));
		assertEquals(7, getCycles(opcode, true));
	}
	
	@Test
	public void testSBC() throws EmulatorException
	{
		int opcode = 0xFD;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testSTA() throws EmulatorException
	{
		int opcode = 0x9D;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	private int getCycles(int opcode, boolean cross_page) throws EmulatorException
	{
		TimingTestBase test_base = new TimingTestBase();
		test_base.setRegisters(0, (cross_page ? 0xC0 : 0), 0, 0);
		test_base.setCommand(0, opcode, 0x44, 0);
		test_base.execute();
		return test_base.getElapsedCycles();
	}
}
